package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.CategoriesService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.user.annotation.Anoymous;
import io.swagger.annotations.Api;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;




@RestController
@RequestMapping("/shopping")
@Api(tags = "CategoriesController", description = "类目控制层")
public class CategoriesController {

    @Reference(timeout = 3000, check = false, interfaceClass = CategoriesService.class)
    CategoriesService categoriesService;


    @Anoymous
    @GetMapping("/categories")
    public ResponseData getCategories(){
        AllProductCateResponse response = categoriesService.getCategories();
        if(response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
            ResponseUtil responseUtil = new ResponseUtil();
            ResponseData responseData = responseUtil.setData(response.getProductCateDtoList());
            return responseData;
        } else {
            ResponseUtil responseUtil = new ResponseUtil();
            ResponseData responseData = responseUtil.setErrorMsg(response.getMsg());
            return responseData;
        }
    }
}
